home *** CD-ROM | disk | FTP | other *** search
/ SGI Varsity Update 1998 August / SGI Varsity Update 1998 August.iso / dist / dist6.5 / il_dev.idb / usr / include / il / ilError.h.z / ilError.h
C/C++ Source or Header  |  1998-07-29  |  10KB  |  306 lines

  1. #if 0 
  2.  
  3.     Copyright (c) 1991 SGI   All Rights Reserved
  4.     THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
  5.     The copyright notice above does not evidence any
  6.     actual or intended publication of such source code,
  7.     and is an unpublished work by Silicon Graphics, Inc.
  8.     This material contains CONFIDENTIAL INFORMATION that
  9.     is the property of Silicon Graphics, Inc. Any use,
  10.     duplication or disclosure not specifically authorized
  11.     by Silicon Graphics is strictly prohibited.
  12.     
  13.     RESTRICTED RIGHTS LEGEND:
  14.     
  15.     Use, duplication or disclosure by the Government is
  16.     subject to restrictions as set forth in subdivision
  17.     (c)(1)(ii) of the Rights in Technical Data and Computer
  18.     Software clause at DFARS 52.227-7013, and/or in similar
  19.     or successor clauses in the FAR, DOD or NASA FAR
  20.     Supplement.  Unpublished- rights reserved under the
  21.     Copyright Laws of the United States.  Contractor is
  22.     SILICON GRAPHICS, INC., 2011 N. Shoreline Blvd.,
  23.     Mountain View, CA 94039-7311
  24.  
  25. #endif
  26.  
  27. /*
  28.  * ilError.h
  29.  *
  30.  * Error codes, error handling and assertion macros
  31.  * used by the IL library.
  32.  */
  33.  
  34. #ifndef __ilError_h__
  35. #define __ilError_h__
  36.  
  37. #include <ifl/iflError.h>
  38.  
  39. #include <pfmt.h>    /* for definitions of MM_HALT, etc. */
  40.  
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44.  
  45. typedef void (ilErrorHandlerFunc)(void *arg, /* closure arg */
  46.                   int flags, /* includes severity, see pfmt(3)*/
  47.                   const char *msg, va_list args);
  48. typedef ilErrorHandlerFunc *ilErrorHandlerType;
  49.  
  50. extern ilErrorHandlerFunc ilNaiveErrorHandler; /* this is the default */
  51. extern ilErrorHandlerFunc ilRobustErrorHandler;
  52. extern ilErrorHandlerFunc ilSilentErrorHandler;
  53. extern void ilGetErrorHandler(ilErrorHandlerType *handler, void **arg);
  54. extern void ilSetErrorHandler(ilErrorHandlerType newhandler, void *newarg);
  55.  
  56. #ifdef __cplusplus
  57. }
  58. #endif
  59.  
  60. #ifdef __cplusplus
  61.  
  62. extern void ilError(int flags, const char *msg, ...);
  63. extern void ilErrorV(int flags, const char *msg, va_list);
  64. extern void _ilDebug(const char *msg, ...);
  65. extern void _ilSetThreadErrorHandler(ilErrorHandlerType handler, void *arg);
  66. extern void _ilUnsetThreadErrorHandler();
  67.  
  68. //
  69. // Convenience class for automatically saving and restoring
  70. // the il Error handler.
  71. // Usage:
  72. //    {
  73. //        ilSetLocalErrorHandler(my_error_handler, my_arg);
  74. //        ... calls to IL that should use my_error_handler ...
  75. //    } // original error handler is restored when object goes out of scope
  76.  
  77. class ilSetLocalErrorHandler {
  78. public:
  79.     ilSetLocalErrorHandler(ilErrorHandlerType handler, void *arg)
  80.     {
  81.         ilGetErrorHandler(&old_handler, &old_arg);
  82.         ilSetErrorHandler(handler, arg);
  83.     }
  84.     /* non-virtual, since always on stack */
  85.     ~ilSetLocalErrorHandler()
  86.     {
  87.         ilSetErrorHandler(old_handler, old_arg);
  88.     }
  89. protected:
  90.     ilErrorHandlerType old_handler;
  91.     void *old_arg;
  92. };
  93.  
  94. //
  95. // Convenience class for temporarily configuring IFL
  96. // to call IL's error handling routine on error.
  97. // Declare one of these objects in the scope where
  98. // this behavior is desired.  Example:
  99. //
  100. //    {
  101. //        iflSetLocalErrorHandlerIL();
  102. //        ... calls to IFL functions which should call ilError on error ...
  103. //    } // original IFL handling restored when object goes out of scope
  104. //
  105. class iflSetLocalErrorHandlerIL : public iflSetLocalErrorHandler {
  106. public:
  107.     iflSetLocalErrorHandlerIL()
  108.     : iflSetLocalErrorHandler(call_ilError, NULL) {}
  109. private:
  110.     static void call_ilError(void *, int flags, const char *fmt, va_list args)
  111.     {
  112.     ilErrorV(flags, fmt, args);
  113.     }
  114. };
  115.  
  116. #endif /* __cplusplus */
  117.  
  118.  
  119. /*
  120.  * Assertion macros:
  121.  *    ilAssert() -- logically impossible conditions, elided from shipped code
  122.  *    ilAlwaysAssert() -- logically impossible conditions,
  123.  *              kept (but less verbose) in shipped code
  124.  */
  125. extern void __ilAssert(const char *, const char *, int);
  126. #ifdef NDEBUG
  127. #define ilAssert(EX) ((void)0)
  128. #define ilAlwaysAssert(EX) ((EX)?((void)0):__ilAssert(0,__FILE__,__LINE__))
  129. #define ilDebug(args) ((void)0)
  130. #else /* !NDEBUG */
  131. #define ilAssert(EX)       ((EX)?((void)0):__ilAssert( # EX ,__FILE__,__LINE__))
  132. #define ilAlwaysAssert(EX) ((EX)?((void)0):__ilAssert( # EX ,__FILE__,__LINE__))
  133. #define ilDebug(args) _ilDebug args
  134. #endif /* !NDEBUG */
  135.  
  136.  
  137. /* ilStatus encodes status return values and object states.  There are
  138.  * three components of an ilStatus code:
  139.  *
  140.  *     unsigned int mainstatus:12 -- il status code
  141.  *     unsigned int subDomain:4   -- domain of subStatus
  142.  *     unsigned int subStatus:16  -- subdomain status code
  143.  *
  144.  * mainstatus encodes a main status code; subStatus encodes an elaboration of
  145.  * the main status code from another domain.  For example: status might
  146.  * be ilOPENFAILED and subStatus might be ENOFILE to indicate why il
  147.  * returned ilOPENFAILED.  In order to determine what subStatus means
  148.  * one must examine subdomain to see whether subStatus contains UNIX errno's,
  149.  * etc.
  150.  *
  151.  * The completely 0 status code, ilOKAY, is reserved.  This makes it
  152.  * easier for most cases in which the caller does not care
  153.  * about the specific value, but only wants to compare with ilOKAY.
  154.  *
  155.  * Note: this file is included by C code so general comments must use
  156.  *       the C commenting convention.
  157.  */
  158.  
  159. enum ilStatus {
  160.     ilOKAY = 0
  161.     /* Other values are really composed of fields as described above... */
  162. };
  163. #ifndef __cplusplus
  164. typedef enum ilStatus ilStatus;
  165. #endif
  166.  
  167.  
  168. /*
  169.  * Possible values for mainstatus field of an ilStatus...
  170.  */
  171. enum ilMainStatus {
  172.     ilBADFILEREAD = 1,             /* Error reading from file */
  173.     ilBADFILEWRITE = 2,     /* Error writing to file */
  174.     ilBADMALLOC = 3,             /* malloc() or new returned NULL */
  175.     ilBADIMGFMT = 4,             /* Bad image file format */
  176.     ilBADDIMS = 5,             /* Bad dimensions */
  177.     ilBADOBJ = 6,             /* Bad object on construction */
  178.     ilBADATTR = 7,             /* Bad attributes */
  179.     ilFMTUNSUP = 8,             /* Unsupported file format */
  180.     ilBADPIXTYPE = 9,             /* Bad pixel type */
  181.     ilBADCONFIG = 10,             /* Unsupported configuration */
  182.     ilNORANDOMSEEK = 11,     /* Can't do random seek */
  183.     ilBADSEEK = 12,             /* Error seeking on file */
  184.     ilBADDECODE = 13,             /* Failure on decompression */
  185.     ilREADONLY = 14,             /* Object is not writable */
  186.     ilBADFIELDSET = 15,     /* Failed to set field in file header */
  187.     ilBADCOMPRESSION = 16,     /* Invalid image compression */
  188.     ilNULLOBJ = 17,             /* NULL object passed as parameter */
  189.     ilBADINPUT = 18,             /* Invalid input passed */
  190.     ilBADCOLFMT = 19,           /* Bad color format */
  191.     ilBADOP = 20,             /* Bad operation attempted */
  192.     ilBADFILEOPEN = 21,     /* Error opening file */
  193.     ilBADMAGIC = 22,             /* Invalid magic number in file */
  194.     ilEMPTYFILE = 23,             /* File is empty */
  195.     ilDATACLIPPED = 24,     /* Data has been clipped */
  196.     ilOUTOFBOUND = 25,             /* Parameter(s) out of bounds */
  197.     ilTOOMANYLOCKED = 26,     /* Too many pages locked in image cache */
  198.     ilLUTSIZEMISMATCH = 27,     /* No. of channels in lut&image incompatible */
  199.     ilZERODIVIDE = 28,             /* Attempted to divide by zero */
  200.     ilUNSUPPORTED = 29,     /* Attempted operation is unsupported */
  201.     ilBADPAGEDIMS = 30,        /* TIFF page dims must be multiples of 8*/
  202.     ilBADTIFFDIR = 31,         /* Could not index into TIFF directory */
  203.     ilNOTRESIDENT = 32,     /* Page is not resident in cache */
  204.     ilHWACCELFAIL = 33,        /* Unable to complete hw accel operation */
  205.     ilHWACCELNEVER = 34,    /* Unable to complete hw accel operation */
  206.     ilPARKED = 35,        /* Request has been parked (don't ask) */
  207.     ilUNIMPLEMENTED = 36,    /* Unimplemented */
  208.     ilIFL_ERROR = 37,        /* IFL error */
  209.     ilFAILED = 38,        /* Operation failed */
  210.     ilNOTLOCKED = 39,         /* Unlocked ilLockRequest */
  211.     ilBADINPUTSTATUS = 40,     /* Input image has bad status */
  212.     ilABORTED = 41,         /* Operation was aborted */
  213.     ilAPPROXIMATE = 42        /* Result is not exact */
  214.  
  215.     /* if values are added here, they must be added to ilMainStatusToString */
  216. };
  217. #ifndef __cplusplus
  218. typedef enum ilMainStatus ilMainStatus;
  219. #endif
  220.  
  221. /*
  222.  * Possible values for subDomain field of an ilStatus...
  223.  */
  224. enum ilSubDomain {
  225.     ilSubDomainNONE    = iflSubDomainNONE,
  226.                 /* no subdomain; subStatus not meaningful */
  227.     ilSubDomainUNIX    = iflSubDomainUNIX,
  228.                 /* subStatus encodes UNIX errno */
  229.     ilSubDomainIFL    = iflLastSubDomain+1,
  230.     ilLastSubDomain     = ilSubDomainIFL
  231. };
  232. #ifndef __cplusplus
  233. typedef enum ilSubDomain ilSubDomain;
  234. #endif
  235.  
  236. /* iflStatus encoding functions (only C++ is supported).
  237.  */
  238. #ifdef __cplusplus
  239. inline ilStatus
  240. ilStatusEncode(unsigned int mainstatus,
  241.            unsigned int subDomain = ilSubDomainNONE,
  242.            unsigned int subStatus = 0)
  243. {
  244.     return (ilStatus) (((mainstatus&0x0fff) << 0)
  245.              | ((subDomain &0x000f) << 12)
  246.              | ((subStatus &0xffff) << 16));
  247. }
  248. #endif
  249.  
  250. /* ilStatus decoding functions
  251.  */
  252. #define ilGetMainStatus(ilstatus) ((ilMainStatus)(((ilstatus)>>0) & 0x0fff))
  253. #define ilGetSubDomain(ilstatus)  ((ilSubDomain)(((ilstatus)>>12) & 0x000f))
  254. #define ilGetSubStatus(ilstatus)  ((unsigned int)(((ilstatus)>>16) & 0xffff))
  255.  
  256.  
  257. #ifdef __cplusplus
  258. extern "C" {
  259. #endif
  260.  
  261. /*
  262.  * Composes an error message into a caller-supplied buffer.
  263.  * Puts at most returnbufsize-1 bytes in the buffer, and null-terminates
  264.  * (unless returnbufsize <= 0).
  265.  */
  266. extern char *ilStatusToString(ilStatus status, char buf[], int bufsize);
  267.  
  268. extern const char *ilMainStatusToString(ilMainStatus status);
  269.  
  270. #ifdef __cplusplus
  271. }
  272. #endif
  273.  
  274. /*
  275.  * Convert an iflStatus into an ilStatus (only C++ is supported).
  276.  *
  277.  * If the iflStatus has a subdomain,
  278.  * then change the main code to ilIFL_ERROR (the old main code is lost)
  279.  * and retain the old subdomain and subcode.
  280.  * XXX (If we had a mapping from IFL main codes to IL main codes,
  281.  * we could use that instead of ilIFL_ERROR, but we don't currently).
  282.  *
  283.  * Otherwise (if the subdomain is NONE),
  284.  * set the new main code to ilIFL_ERROR,
  285.  * set the new subdomain to IFL,
  286.  * and set the new subcode to be the old main code.
  287.  */
  288. #ifdef __cplusplus
  289. inline ilStatus ilStatusFromIflStatus(iflStatus iflstatus)
  290. {
  291.     if (iflstatus == iflOKAY)
  292.     return ilOKAY;
  293.  
  294.     if (iflGetSubDomain(iflstatus) != iflSubDomainNONE)
  295.     return ilStatusEncode(ilIFL_ERROR,
  296.                   iflGetSubDomain(iflstatus),
  297.                   iflGetSubStatus(iflstatus));
  298.     else
  299.     return ilStatusEncode(ilIFL_ERROR,
  300.                   ilSubDomainIFL,
  301.                   iflGetMainStatus(iflstatus));
  302. }
  303. #endif
  304.  
  305. #endif /* __ilError_h__ */
  306.